"""
These are Monsoon Exception classes. 

The Monsoon Exception classes are only dependent on the ServerMessageMap
class which provides the error string based on error codes.

NOTE: All Monsoon Exceptions can't call or directly use the ServerLog class
as there would be circular dependencies. We would rather have ServerLog 
dependent on MonsoonException classes and be able to throw exceptions.

In the future, if we need to log error in server log and raise exceptions in 
one shot, we could add helper methods in ServerLog in order to do both in 
one function call.  However, we can't make MonsoonException call ServerLog 
directly to log messages.
"""

# Python standard module imports
import time
import threading

# Monsoon specific imports
from constants import DEFAULT_TIME_FORMAT
#from msgdict import ServerMessageMap


"""
IservicesException:
"""
class IservicesException(Exception):

    # This message can't be located inside any message catelog. It is used
    # only when the MonsoonException class is first initialized.
    MSG_EXCEPT_INIT_ERR = u"System Error: Duplicate initialization of the Monsoon Exception Message Map."


    # Constructor:
    # It takes a message code & all the arguments for the code.
    def __init__ (self, iCode, *args):
        self.iCode = iCode
        self.tvArgs = args
        #self.uErrStr = ServerMessageMap.getFmtMsg(iCode, *args)


    # Need to override this method so that the exception traceback method
    # can get a string of this object if necessary
    def __str__ (self):
        return "self.uErrStr "


    #def toString(self, oTransformFunc):
    #    tvArgsEx = ()
    #    for v in self.tvArgs:
    #        tvArgsEx += (oTransformFunc(v),)
    #    return ServerMessageMap.getFmtMsg(self.iCode, *tvArgsEx)


    # Returns the error code.
    def getCode (self):
        return self.iCode


"""
IservicesSysException:
    These are more like 'assertions' coming from the Monsoon system.

    USAGE: In most of scenarios, we would throw IservicesSysException much
    like using assertion or when there is system corruption error, etc. We 
    would log the error msg into the ServerLog only when the exception is 
    actually caught via ServerLog.logExceptionTraceback () function.
"""
class IservicesSysException (IservicesException): 

    def __init__ (self, iCode, *args):
        IservicesException.__init__ (self, iCode, *args) 

"""
MonsoonUserException:
    This is similar to IservicesSysException except these are for user errors, 
    but not monsoon system errors. This exception can provide shortcuts for 
    us to skip some execution of the business logic, etc, in case user error 
    happens.
"""
class IservicesUserException (IservicesException): 

    def __init__ (self, iCode, *args):
        IservicesException.__init__ (self, iCode, *args) 


